<template>
  <div class="page-wrap">

    <!-- 数字翻牌器 -->
    <div class="wrap">
      <div class="element-wrap">
        <div class="title"> 数字翻牌器 </div>
        <div class="item-wrap">
          <div v-for="(item,index) in rollers" :key="index" class="item">
            <hzx-roller :type="item.type" :start-val="0" :end-val="2020" :autoplay="true" :decimals="3" separator="," font-size="40px" />
            <div class="copy-wrap" @click="copyCode($event,item.code)"> <div> {{ item.code }}</div>  </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 轮播表 -->
    <div class="wrap">
      <div class="element-wrap">
        <div class="title"> 轮播表 </div>
        <div class="item-wrap">
          <div v-for="(item,index) in scrolls" :key="index" class="item">
            <div class="compoment-wrap">
              <hzx-scroll
                :type="item.type"
                :render-data="scrollData"
              />
            </div>
            <div class="copy-wrap" @click="copyCode($event,item.code)">  <div>{{ item.code }}</div>  </div>
          </div>
          <div class="item">increasing...</div>
        </div>
      </div>
    </div>
    <!-- 加载 -->
    <div class="wrap">
      <div class="element-wrap">
        <div class="title"> 加载中 </div>
        <div class="item-wrap">
          <div v-for="(item,index) in loading" :key="index" class="item">
            <hzx-loading
              :type="item.type"
              :scale="2"
              :duration="2000"
            />
            <div class="copy-wrap" @click="copyCode($event,item.code)">  <div>{{ item.code }}</div>  </div>
          </div>
          <div class="item">increasing...</div>
        </div>
      </div>
    </div>
    <!-- 轮播指示器 -->
    <div class="wrap">
      <div class="element-wrap">
        <div class="title"> 轮播控制、指示器 </div>
        <div class="item-wrap">
          <div v-for="(item,index) in indicator" :key="index" class="item">
            <!-- 指示器 -->
            <div class="indicator-item">
              <hzx-indicator :tabs="tabs" :index="curIndex" @changeTab="changeTab" />
            </div>
            <!-- 轮播内容 -->
            <div class="indicator-content">
              {{ tabs[curIndex] }}的内容
            </div>
            <div class="copy-wrap" @click="copyCode($event,item.code)">  <div>{{ item.code }}</div>  </div>
          </div>
          <div class="item">increasing...</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Clipboard from 'clipboard'
export default {
  name: 'Element',
  props: {},
  data() {
    return {
      titles: [
        { title: '标题' },
        { title: '标题1' }
      ],
      rollers: [
        { type: 'r-type1', code: `<hzx-roller type='r-type1' />` },
        { type: 'r-type2', code: `<hzx-roller type='r-type2' />` }
      ],
      scrolls: [
        { type: 's-type1', code: `<hzx-scroll type='s-type1' />` }
      ],
      loading: [
        { type: 'l-type1', code: `<hzx-loading type='l-type1' />` }
      ],

      tabs: ['演示一', '演示二', '演示三'],
      curIndex: 0,
      indicator: [
        { code: `<hzx-indicator :tabs="tabs" :index="curIndex" @changeTab="changeTab" />`,
          code1: `changeTab(index) { console.log(index) }," />`
        }
      ],

      scrollData: [
        { name: '济南市济南市济南市济南市', value: 50 },
        { name: '青岛市青岛市青岛市青岛市', value: 57 },
        { name: '菏泽市菏泽市菏泽市菏泽市', value: 60 },
        { name: '济南市济南市济南市济南市', value: 50 },
        { name: '青岛市青岛市青岛市青岛市', value: 57 },
        { name: '济南市济南市济南市济南市', value: 50 },
        { name: '青岛市青岛市青岛市青岛市', value: 57 },
        { name: '德州市德州市德州市德州市', value: 90 }
      ]
    }
  },
  methods: {
    // 当前显示内容指示器
    changeTab(index) {
      this.curIndex = index
    },
    /**
     * @param {Object} e 事件
     * @param {String} text 赋值内容
     */
    copyCode(e, text) {
      const clipboard = new Clipboard(e.target, { text: () => text })
      console.log('Sss')
      clipboard.on('success', (e) => {
        window.alert('复制成功')
        // 释放内存
        clipboard.off('error')
        clipboard.off('success')
        clipboard.destroy()
      })
      clipboard.on('error', e => {
        // 不支持复制
        window.alert('复制失败')
        // 释放内存
        clipboard.off('error')
        clipboard.off('success')
        clipboard.destroy()
      })
      clipboard.onClick(e)
    }
  }
}
</script>

<style lang="less" scoped>
.page-wrap{
    width: 100%;
    overflow: hidden;
}
.wrap{
    width: 100%;
    height: 100%;
    display: flex;
}
.element-wrap{
    width: 100%;
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .item-wrap{
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      margin-top: 20px;
      padding: 10px;
      justify-content: space-between;
      .item{
       width: 48%;
       height: 250px;
       justify-content: space-around;
       display: flex;
       flex-direction: column;
       align-items: center;
       position: relative;
      }
    }
    .compoment-wrap{
        background-color: #000000;
        width: 80%;
        margin-left:10%;
        height: 200px;
    }
    .copy-wrap{
         display: flex;
         justify-content: center;
         background-color:#000;
         border-radius: 6px;
         align-items: center;
         height: 30px;
         width: 80%;
         margin-left: 10%;
         color:#fff;
     }
}

.title{
    width:100% ;
    height: 15%;
    margin-left: 10%;
    position: relative;
    display: flex;
    font-weight: 600;
    color:#000;
    font-size: 14px;
    justify-content: space-between;
    align-items: center;
    .btns{
        display: flex;
        flex-wrap: nowrap;
        width: 70%;
        margin-right: 5%;
        justify-content: space-around;
        .btns-item{
            display: flex;
            flex-wrap: nowrap;
            align-items: center;
        }
        input{
            width: 50%;
            height: 30px;
            margin-left: 20px;
            padding: 5px 10px;
            border-radius: 10px;
        }
    }
}
.title::before{
    content: "";
    width: 5px;
    position: absolute;
    height: 35%;
    background-color: rgb(24 144 255);
    left: -10px;
}
.content{
    width: 100%;
    height: 85%;
}
.indicator-item{
    height: 35px;
    position: absolute;
    top: 20px;
    right: 40px;
}
.indicator-content{
    width: 100%;
    display: flex;
    justify-content: center;
    height: 100px;
}
</style>
